{minimum_otp_vsn, "R24"}.

{deps, [
        %% Core dependencies
        {uuid, "2.0.5", {pkg, uuid_erl}},
        {types, "~> 0.1.8"},
        {opentelemetry_api, "1.2.1"},
        telemetry
        %% Applications under test
        %% {hbbft, {git, "git://github.com/helium/erlang-hbbft", {branch, "master"}}}
        %% {riak_ensemble, {git, "git://github.com/cmeiklejohn/riak_ensemble", {branch, "partisan"}}},
        %% {paxoid, {git, "git://github.com/cmeiklejohn/paxoid", {branch, "partisan"}}},
        %% {lashup, {git, "git://github.com/cmeiklejohn/lashup", {branch, "partisan"}}},
        %% {hbbft, {git, "git://github.com/helium/erlang-hbbft", {branch, "master"}}},
        %% {zraft_lib, {git, "git://github.com/cmeiklejohn/zraft_lib", {branch, "master"}}}
       ]}.

{dialyzer_base_plt_apps, [
  kernel, stdlib, erts, sasl, eunit, syntax_tools, compiler, crypto
]}.
{xref_checks, [undefined_function_calls]}.
{xref_ignores, [
  eredis,
  jsx,
  {partisan_peer_discovery_agent, format_status, 2}
]}.

{cover_enabled, true}.
{cover_opts, [verbose]}.
{cover_export_enabled, true}.
{covertool, [{coverdata_files, ["ct.coverdata"]}]}.

{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.

{project_plugins, [
    rebar3_proper,
    rebar3_ex_doc,
    rebar3_hex
]}.

{shell, [
  {erl_opts, [warnings_as_errors]},
  {apps, [partisan]},
  {config, "config/sys.config"}
]}.


{relx, [
    {release, {partisan, "partisan"}, [
        %% Erlang
        sasl,
        crypto,
        inets,
        tools,
        runtime_tools,
        os_mon,
        debugger,
        %% Third-parties
        types,
        uuid,
        opentelemetry_api,
        telemetry,
        partisan
    ]},
    {dev_mode, false},
    {include_src, false},
    {include_erts, true},
    {extended_start_script, true},
    {overlay_vars, "config/vars.config"}
]}.

{profiles, [
    {node1, [
        {deps, [
            recon,
            observer_cli
        ]},
        {relx, [
            {dev_mode, false},
            {mode, prod},
            {include_src, false},
            {include_erts, true},
            {sys_config, "config/node1/sys.config"},
            {vm_args, "config/node1/vm.args"},
            {overlay, [
                {mkdir, "{{platform_etc_dir}}"},
                {copy,
                    "config/_ssl/server/cacerts.pem",
                    "{{platform_etc_dir}}/ssl/server/cacerts.pem"
                },
                {copy,
                    "config/_ssl/server/keycert.pem",
                    "{{platform_etc_dir}}/ssl/server/keycert.pem"
                },
                {copy,
                    "config/_ssl/server/key.pem",
                    "{{platform_etc_dir}}/ssl/server/key.pem"
                },
                {copy,
                    "config/_ssl/client/cacerts.pem",
                    "{{platform_etc_dir}}/ssl/client/cacerts.pem"
                },
                {copy,
                    "config/_ssl/client/keycert.pem",
                    "{{platform_etc_dir}}/ssl/client/keycert.pem"
                },
                {copy,
                    "config/_ssl/client/key.pem",
                    "{{platform_etc_dir}}/ssl/client/key.pem"
                }
            ]}
        ]}
    ]},
    {node2, [
        {deps, [
            recon,
            observer_cli
        ]},
        {relx, [
            {dev_mode, false},
            {mode, prod},
            {include_src, false},
            {include_erts, true},
            {sys_config, "config/node2/sys.config"},
            {vm_args, "config/node2/vm.args"},
            {overlay, [
                {mkdir, "etc"},
                {mkdir, "{{platform_etc_dir}}/ssl"},
                {copy,
                    "config/_ssl/server/cacerts.pem",
                    "{{platform_etc_dir}}/ssl/server/cacerts.pem"
                },
                {copy,
                    "config/_ssl/server/keycert.pem",
                    "{{platform_etc_dir}}/ssl/server/keycert.pem"
                },
                {copy,
                    "config/_ssl/server/key.pem",
                    "{{platform_etc_dir}}/ssl/server/key.pem"
                },
                {copy,
                    "config/_ssl/client/cacerts.pem",
                    "{{platform_etc_dir}}/ssl/client/cacerts.pem"
                },
                {copy,
                    "config/_ssl/client/keycert.pem",
                    "{{platform_etc_dir}}/ssl/client/keycert.pem"
                },
                {copy,
                    "config/_ssl/client/key.pem",
                    "{{platform_etc_dir}}/ssl/client/key.pem"
                }
            ]}
        ]}
    ]},
    {node3, [
        {deps, [
            recon,
            observer_cli
        ]},
        {relx, [
            {dev_mode, false},
            {include_src, false},
            {include_erts, true},
            {sys_config, "config/node3/sys.config"},
            {vm_args, "config/node3/vm.args"},
            {overlay, [
                {mkdir, "etc"},
                {mkdir, "{{platform_etc_dir}}/ssl"},
                {copy,
                    "config/_ssl/server/cacerts.pem",
                    "{{platform_etc_dir}}/ssl/server/cacerts.pem"
                },
                {copy,
                    "config/_ssl/server/keycert.pem",
                    "{{platform_etc_dir}}/ssl/server/keycert.pem"
                },
                {copy,
                    "config/_ssl/server/key.pem",
                    "{{platform_etc_dir}}/ssl/server/key.pem"
                },
                {copy,
                    "config/_ssl/client/cacerts.pem",
                    "{{platform_etc_dir}}/ssl/client/cacerts.pem"
                },
                {copy,
                    "config/_ssl/client/keycert.pem",
                    "{{platform_etc_dir}}/ssl/client/keycert.pem"
                },
                {copy,
                    "config/_ssl/client/key.pem",
                    "{{platform_etc_dir}}/ssl/client/key.pem"
                }
            ]}
        ]}
    ]},
    {node4, [
        {deps, [
            recon,
            observer_cli
        ]},
        {relx, [
            {dev_mode, false},
            {include_src, false},
            {include_erts, true},
            {sys_config, "config/node4/sys.config"},
            {vm_args, "config/node4/vm.args"},
            {overlay, [
                {mkdir, "etc"},
                {mkdir, "{{platform_etc_dir}}/ssl"},
                {copy,
                    "config/_ssl/server/cacerts.pem",
                    "{{platform_etc_dir}}/ssl/server/cacerts.pem"
                },
                {copy,
                    "config/_ssl/server/keycert.pem",
                    "{{platform_etc_dir}}/ssl/server/keycert.pem"
                },
                {copy,
                    "config/_ssl/server/key.pem",
                    "{{platform_etc_dir}}/ssl/server/key.pem"
                },
                {copy,
                    "config/_ssl/client/cacerts.pem",
                    "{{platform_etc_dir}}/ssl/client/cacerts.pem"
                },
                {copy,
                    "config/_ssl/client/keycert.pem",
                    "{{platform_etc_dir}}/ssl/client/keycert.pem"
                },
                {copy,
                    "config/_ssl/client/key.pem",
                    "{{platform_etc_dir}}/ssl/client/key.pem"
                }
            ]}
        ]}
    ]},
    {test, [
       {erl_opts, [
          nowarn_export_all,
          nowarn_unused_type,
          nowarn_deprecated_function,
          debug_info
        ]},
        {extra_src_dirs, ["protocols", "test/otp"]},

        {deps, [
          {eredis,
            {git, "https://github.com/wooga/eredis.git", {tag, "master"}}
          },
          {jsx, "3.1.0"},
          {proper, "1.4.0"},
          recon
        ]},

        {relx, [{release, {partisan, "5.0.0-beta.19"}, [eredis, partisan]},
               {extended_start_script, true},

               {dev_mode, true},
               {include_erts, false},

               {sys_config, "config/sys.config"},
               {vm_args, "config/vm.args"},

               {overlay, [{mkdir, "log/sasl"},
                          {mkdir, "data/"},
                          {copy, "bin/env", "bin"}
              ]}
        ]}
    ]},
    {lint,  [
        {erl_opts, [
          warnings_as_errors,
          nowarn_export_all,
          nowarn_deprecated_function,
          debug_info
        ]},
        {plugins, [rebar3_lint]}
    ]}
]}.


{hex, [
  {doc, #{provider => ex_doc}}
]}.


{ex_doc, [
  {name, "Partisan"},
  {source_url, <<"https://github.com/lasp-lang/partisan">>},
  {extras, [
    <<"README.md">>,
    <<"doc_extras/cheatsheet.cheatmd">>,
    <<"doc_extras/telemetry.md">>,
    <<"LICENSE">>,
    <<"CHANGELOG.md">>,
    <<"CODE_OF_CONDUCT.md">>
  ]},
  {main, <<"README.md">>},
  {logo, "assets/partisan_isotype.png"},
  {extra_section, "Pages"},
  {api_reference, true},
  {groups_for_extras, #{
      <<"Introduction">> => [
      ],
      <<"Tutorials">> => [],
      <<"How-to Guides">> => [],
      <<"Deployment">> => [],
      <<"Technical Reference">> => []
  }},
  {groups_for_modules, [
      {<<"API">>, [
        partisan,
        partisan_config,
        partisan_peer_service
      ]},
      {<<"OTP">>, [
        partisan_erpc,
        partisan_gen,
        partisan_gen_event,
        partisan_gen_server,
        partisan_gen_statem,
        partisan_gen_supervisor,
        partisan_monitor,
        partisan_proc_lib,
        partisan_rpc,
        partisan_rpc_backend,
        partisan_sys,
        partisan_test_server
      ]},
      {<<"Peer Discovery Agent">>, [
        partisan_peer_discovery_agent,
        partisan_peer_discovery_list,
        partisan_peer_discovery_dns
      ]},
      {<<"Peer Service (Sampling|Membership)">>, [
        partisan_peer_service,
        partisan_peer_service_manager,
        partisan_peer_service_sup,
        partisan_peer_service_events,
        partisan_peer_service_console,
        partisan_peer_service_client,
        partisan_peer_service_server,
        partisan_remote_ref
      ]},
      {<<"Sampling|Membership Protocols">>, [
        partisan_pluggable_peer_service_manager,
        partisan_hyparview_peer_service_manager,
        partisan_client_server_peer_service_manager,
        partisan_static_peer_service_manager
      ]},
      {<<"Pluggable Membership Strategy">>, [
        partisan_membership_set,
        partisan_membership_strategy,
        partisan_full_membership_strategy,
        partisan_scamp_v1_membership_strategy,
        partisan_scamp_v2_membership_strategy
      ]},
      {<<"Gossip-based Broadcast">>, [
        partisan_plumtree_backend,
        partisan_plumtree_broadcast,
        partisan_plumtree_broadcast_handler,
        partisan_plumtree_util
      ]},
      {<<"Routing Backend">>, [
        partisan_acknowledgement_backend,
        partisan_causality_backend
      ]},
      {<<"Connection Management">>, [
        partisan_peer_connections,
        partisan_peer_socket,
        partisan_acceptor_pool,
        partisan_acceptor_socket_pool_sup,
        partisan_acceptor_socket
      ]},
      {<<"Orchestration">>, [
        partisan_orchestration_strategy,
        partisan_orchestration_backend,
        partisan_compose_orchestration_strategy,
        partisan_kubernetes_orchestration_strategy
      ]},
      {<<"Tracing">>, [
        partisan_trace_file,
        partisan_trace_orchestrator
      ]},
      {<<"Scaffolding">>, [
        partisan_app,
        partisan_sup
      ]},
      {<<"Utils">>, [
        partisan_util,
        partisan_inet,
        partisan_vclock,
        partisan_transform,
        partisan_transformed_module,
        partisan_analysis,
        partisan_logger
      ]},
      {<<"Deprecated">>, [
        partisan_otp_adapter,
        partisan_gen_fsm
      ]}

  ]}
]}.



{elvis,
 [#{dirs => ["src"],
       filter => "*.erl",
       rules => [
                 %% {elvis_style, line_length,
                 %%  #{ignore => [],
                 %%    limit => 80,
                 %%    skip_comments => false}},
                 {elvis_style, no_tabs},
                 {elvis_style, no_trailing_whitespace},
                 {elvis_style, macro_names, #{ignore => []}},
                 %% {elvis_style, macro_module_names},
                 {elvis_style, operator_spaces, #{rules => [{right, ","},
                                                            {right, "++"},
                                                            {left, "++"}]}},
                 %% {elvis_style, nesting_level, #{level => 3}},
                 {elvis_style, god_modules,
                  #{limit => 25,
                    ignore => []}},
                 {elvis_style, no_if_expression},
                 %% {elvis_style, invalid_dynamic_call, #{ignore => []}},
                 {elvis_style, used_ignored_variable},
                 {elvis_style, no_behavior_info},
                 {
                   elvis_style,
                   module_naming_convention,
                   #{regex => "^[a-z]([a-z0-9]*_?)*(_SUITE)?$",
                     ignore => []}
                 },
                 {
                   elvis_style,
                   function_naming_convention,
                   #{regex => "^([a-z][a-z0-9]*_?)*$"}
                 },
                 {elvis_style, state_record_and_type},
                 {elvis_style, no_spec_with_records}
                 %% {elvis_style, dont_repeat_yourself, #{min_complexity => 10}}
                 %% {elvis_style, no_debug_call, #{ignore => []}}
                ]
      },
     #{dirs => ["."],
       filter => "Makefile",
       rules => [{elvis_project, no_deps_master_erlang_mk, #{ignore => []}},
                 {elvis_project, protocol_for_deps_erlang_mk, #{ignore => []}}]
      },
     #{dirs => ["."],
       filter => "rebar.config",
       rules => [{elvis_project, no_deps_master_rebar, #{ignore => []}},
                 {elvis_project, protocol_for_deps_rebar, #{ignore => []}}]
      }
    ]
}.
